//package com.keyinong.caizhengting.dingdanfragment;
//
//import java.util.ArrayList;
//
//import org.apache.http.Header;
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import android.content.Context;
//import android.content.Intent;
//import android.content.SharedPreferences;
//import android.os.Bundle;
//import android.support.v4.app.Fragment;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.AdapterView;
//import android.widget.AdapterView.OnItemClickListener;
//import android.widget.ListView;
//import android.widget.ScrollView;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.handmark.pulltorefresh.library.PullToRefreshBase;
//import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
//import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
//import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
//import com.keyinong.caizhengting.R;
//import com.keyinong.caizhengting.Tools.HttpTools;
//import com.keyinong.caizhengting.Tools.NetWorkUtil;
//import com.keyinong.caizhengting.Tools.Utility;
//import com.keyinong.caizhengting.adapter.MyteamorderAdapter;
//import com.keyinong.caizhengting.entity.MyorderEntity;
//import com.keyinong.caizhengting.view.DingdandetailActivity;
//import com.keyinong.caizhengting.view.MyorderteamorderActivity;
//import com.loopj.android.http.JsonHttpResponseHandler;
//
//public class Personalorder extends Fragment{
//
////	private MyorderAdapter myorderAdapter;
//	private MyteamorderAdapter myteamorderAdapter;
////	/**是否团队订餐*/
////	String teamorderid;
//	/**订单列表*/
//	private ListView lv;
//	/** 刷新 */
//	private PullToRefreshScrollView pull_myorder;
//	/**份数*/
//	private int shuliang;
//	/**总价*/
//	private double zongjia;
//	/**获得数据*/
//	ArrayList<MyorderEntity> infolist;
//	HttpTools httptools=null;
//	String token = "";
//	int offset = 0;
//	int page = 8;
//	String fee;
//	double allprice;
//	private TextView tv_state;
//	@Override
//	public View onCreateView(LayoutInflater inflater, ViewGroup container,
//			Bundle savedInstanceState) {
//		return inflater.inflate(R.layout.personalorder, null);
//	}
//	@Override
//	public void onActivityCreated(Bundle savedInstanceState) {
//		// TODO Auto-generated method stub
//		super.onActivityCreated(savedInstanceState);
//		SharedPreferences sp = getActivity().getSharedPreferences("spReg",
//				Context.MODE_PRIVATE);
//		token = sp.getString("data", "");
//		pull_myorder=(PullToRefreshScrollView)getView().findViewById(R.id.pull_wodedingdan);
//		pull_myorder.setMode(Mode.BOTH);
//		pull_myorder.setOnRefreshListener(onrefresh);
//		lv=(ListView)getView().findViewById(R.id.lv_dingdan);
//		lv.setOnItemClickListener(itemclicke);
//		tv_state=(TextView)getView().findViewById(R.id.tv_state);
//		Dingdan();
//		//		Shuliang();
//	}
//	//	private void Shuliang() {
//	//		infolist=new ArrayList<MyorderEntity>();
//	//		if (httptools == null) {
//	//			httptools = new HttpTools(getActivity());
//	//		}
//	//		httptools.myorder(token, ""+page,""+ offset, new JsonShuliang());	
//	//	}
//	//	public class JsonShuliang extends JsonHttpResponseHandler {
//	//		@Override
//	//		public void onSuccess(int statusCode, Header[] headers,
//	//				JSONObject response) {
//	//			// TODO Auto-generated method stub
//	//			super.onSuccess(statusCode, headers, response);
//	//			try {
//	//				boolean code = response.getBoolean("code");
//	//				String msg = response.getString("msg");
//	//				if(code==true){
//	//					JSONArray array = response.getJSONArray("data");
//	//					for (int i = 0; i < array.length(); i++) {
//	//						JSONObject data = array.getJSONObject(i);
//	//						JSONArray array2 = data.getJSONArray("details");
//	//						for(int j=0;j<array2.length();j++){
//	//							JSONObject detail = array2.getJSONObject(j);
//	//							String fenshu = detail.getString("amount"); 
//	//							shuliang += Integer.parseInt(fenshu);
//	//							Log.i("zq", "shuliang---"+shuliang);
//	//							infolist.add(new MyorderEntity(""+shuliang));
//	//						}
//	//					}
//	//				}
//	//			} catch (JSONException e) {
//	//				e.printStackTrace();
//	//			}
//	//		}
//	//	}
//	
//	private OnItemClickListener itemclicke = new OnItemClickListener() {
//
//		@Override
//		public void onItemClick(AdapterView<?> parent, View view,final int position,
//				long id) {
//			Intent intent = new Intent();
//			intent.putExtra("orderid", infolist.get(position).getId());	
////			Log.i("zq", "test-------------------");
//			if(infolist.get(position).getTeamorderid().equals("0")||infolist.get(position).getTeamorderid().equals("null")){
//				intent.setClass(getActivity(), DingdandetailActivity.class);
//				startActivity(intent);	
//			}else if(!infolist.get(position).getTeamorderid().equals("0")||infolist.get(position).getTeamorderid().equals("null")) {
//				intent.setClass(getActivity(), MyorderteamorderActivity.class);
//				startActivity(intent);	
//			}
//
//		}
//	};
//	private void Dingdan() {
//		infolist=new ArrayList<MyorderEntity>();
//
//		//		Log.e("shi", "token---" + token);
//		if (httptools == null) {
//			httptools = new HttpTools(getActivity());
//		}
//		httptools.myorder(token, ""+page,""+ offset, "0",new JsonDingdan());	
//	}
//	public class JsonDingdan extends JsonHttpResponseHandler {
//		@Override
//		public void onSuccess(int statusCode, Header[] headers,
//				JSONObject response) {
//			// TODO Auto-generated method stub
//			super.onSuccess(statusCode, headers, response);
//			try {
//				boolean code = response.getBoolean("code");
//				String msg = response.getString("msg");
//				if(code==true){
//					Log.i("info", "myorder---"+response.toString());
//					JSONArray array = response.getJSONArray("data");
//					for (int i = 0; i < array.length(); i++) {
//						JSONObject data = array.getJSONObject(i);
//						String id=data.getString("id");
//						String order_time=data.getString("order_time");
//						String state=data.getString("state");	
//						String paymodeid=data.getString("paymodeid");
//						String teamid=data.getString("teamid");
//						String total = data.getString("total");
//						String fee = data.getString("fee");
//						String refund = data.getString("refund");
//						allprice =Double.parseDouble(total)+Double.parseDouble(fee);
////						Log.i("zq", "allprice---"+allprice);
//						JSONArray array2 = data.getJSONArray("details");
//						//						for(int k=0;k<1;k++){
//						//							Log.i("zq", "length1***"+array2.length());					
//						if(array2.length()!=0){
//							JSONObject details = array2.getJSONObject(0);
//							//							Log.i("zq", "details"+details);
//							String name = details.getString("name");
//							String amount = details.getString("amount"); 
//							String price = details.getString("price");
//							for(int j=0;j<array2.length();j++){
//								JSONObject detail = array2.getJSONObject(j);
//								String fenshu = detail.getString("amount");
//								String jiage = detail.getString("price");
//								zongjia += Integer.parseInt(fenshu)*Double.parseDouble(jiage);
////								Log.i("zq", "zongjia"+zongjia);
//								shuliang += Integer.parseInt(fenshu);
//							}
//							int count = array2.length();
//							infolist.add(new MyorderEntity(id, state, name, amount, price, order_time,""+shuliang,""+total,paymodeid,teamid,count,""+allprice,refund));
//							zongjia=0.0;
//							shuliang=0;
//						}
//					}
//				}else{
//					Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
//				}
//				if(infolist.size()==0){
////					tv_state.setText("已无更多订单");
//					tv_state.setVisibility(View.VISIBLE);
//				}else{
//					tv_state.setVisibility(View.GONE);
//				}
//					myteamorderAdapter=new MyteamorderAdapter(getActivity(), infolist);
//					lv.setAdapter(myteamorderAdapter);
//					lv.setDivider(null);
//					Utility.setListViewHeightBasedOnChildren(lv);	
//				pull_myorder.onRefreshComplete();
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
//		}
//	}
//
//	// 上下拉刷新
//	private OnRefreshListener2<ScrollView> onrefresh = new OnRefreshListener2<ScrollView>() {
//
//		@Override
//		public void onPullDownToRefresh(
//				PullToRefreshBase<ScrollView> refreshView) {
//			offset = 0;
//			infolist.clear();
//			//				shuliang=0;
//			httptools.myorder(token,  page + "", offset + "", "0",
//					new JsonDingdan());
//			if (NetWorkUtil.isNetwork(getActivity()) == false) {
//				Toast.makeText(getActivity(),  "当前网络不可用", Toast.LENGTH_SHORT).show();
//				pull_myorder.onRefreshComplete();
//				return;
//			}
//		}
//
//		@Override
//		public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
//			offset += page;
//			//				shuliang=0;
//			httptools.myorder(token, page + "", offset + "", "0",
//					new JsonDingdan());
//			if (NetWorkUtil.isNetwork(getActivity()) == false) {
//				pull_myorder.onRefreshComplete();
//				return;
//			}
//
//		}
//
//	};
//
//}
